/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */

package cn.webrx;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * <p>Project: jse2303 - Map1
 * <p>Powered by webrx On 2023-07-20 09:07:36
 * <p>描述：<p>
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Map1 {
    public static void main(String[] args) {
        //Map map = new HashMap();
        //Map<String,Object> map = new HashMap<String, Object>();
        Map<String, Integer> m = new HashMap<>();
        System.out.println(m.size());//0
        System.out.println(m.isEmpty()); //true

        //添加元素 key重复，值覆盖，保持key唯一
        m.put("c", 110);
        m.put("java", 100);
        m.put("python", 120);
        m.put("php", 20);
        m.put("java", 150);

        //Map<String, Integer> ms = new HashMap<>();
        //ms.put("a", 1);
        //ms.put("b", 2);
        //ms.put("c", 3);
        //添加一个map集合的元素
        //m.putAll(ms);
        //m.put("java", null);
        //删除
        //m.remove("java");
        //var v = m.putIfAbsent("java", 1000);
        //
        //System.out.println(v);
        //System.out.println(m.size());
        //System.out.println(m);

        //判断
        //System.out.println(m.containsKey("java"));
        //System.out.println(m.containsValue(100));
        //System.out.println(m.containsValue(1000));
        //System.out.println(m.isEmpty());


        //删除清空
        //m.clear();
        //System.out.println(m.remove("java")); //1000
        //System.out.println(m.remove("java"));//null
        //System.out.println(m.remove("java", 150));
        //System.out.println(m);

        //遍历
        //keyset
        Set<String> ks = m.keySet();
        for (String k : ks) {
            //System.out.println(k);
            System.out.printf("m.get(\"%s\") = %d%n", k, m.get(k));
        }

        //values Collection<Integer> List
        //Collection<Integer> vs = m.values();
        var vs = m.values();
        for (int i : vs) {
            System.out.println(i);
        }

        //Set<Map.Entry<String, Integer>> entries = m.entrySet(); 了解
        var entries = m.entrySet();
        for (var e : entries) {
            System.out.println(e);
        }


    }
}
